 /*
 * Created on Tue Jul 22 00:14:44 KST 2008
 */
package BridgeBundle;

import java.util.Properties;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;

public class Activator implements BundleActivator {
	private HelloService hs = null;
	private Worker ws = null;
	private ServiceRegistration svcreg = null;
	private ServiceReference svcref = null;
	
  /* (non-Javadoc)
   * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
   */
  public void start(BundleContext context) throws Exception {
	  Properties sProps = new Properties();
	  hs = new HelloServiceImpl();
	  ws = new Worker();
	  
	  svcreg = context.registerService("BridgeBundle.HelloService", hs , sProps);
	  svcref = context.getServiceReference("BridgeBundle.HelloService");
	  hs = (HelloService)context.getService(svcref);
	  hs.helloMsg();
	  
	  svcreg = context.registerService("BridgeBundle.WorkerInterface", ws , sProps);
	  svcref = context.getServiceReference("BridgeBundle.WorkerInterface");
	  ws = (Worker) context.getService(svcref);
	  ws.connect("127.0.0.1", 1979);
	  
	  //System.out.println("!!!Start. Connection OK!");
	  //ws.sendMessage("Hi~~~!!!\r\n");
	  
	  ws.sendMessage("merong\r\n");
	  
  }

  /* (non-Javadoc)
   * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
   */
  public void stop(BundleContext context) throws Exception {
	  svcreg.unregister();
	  hs.byeMsg();
  }
}